#pragma once

#include "BaseApplication.h"
#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32
#include "../res/resource.h"
#endif
#include "Message.h"
#include "MessageObjectNode.h"

#include <NxOgre.h>
#include <NxOgreOGRE3D.h>
#include <fmod.hpp>
#include <fmod_errors.h>
#include <boost/asio.hpp>
#include "Object.h"
#include "Network.h"
#include "Message.h"
#include <boost/regex.hpp>
#include "Level.h"

using boost::asio::ip::udp;

class mmt_MP_engine : public BaseApplication, public MessageHandler
{
	public:
		mmt_MP_engine(void);
		virtual ~mmt_MP_engine(void);

	protected:
		virtual void			createScene(void);

		bool					frameEnded( const Ogre::FrameEvent& evt );
		bool					frameStarted( const Ogre::FrameEvent& evt );
		void					sendDataEveryFrame();
		bool					frameRenderingQueued( const Ogre::FrameEvent& evt );
		bool					keyPressed( const OIS::KeyEvent& arg );
		bool					keyReleased( const OIS::KeyEvent& arg );
		bool					keyPressedIpInputLabel( const OIS::KeyEvent& arg );

		virtual bool			mouseMoved( const OIS::MouseEvent &arg );
		virtual bool			mousePressed( const OIS::MouseEvent &arg, OIS::MouseButtonID id );
		virtual bool			mouseReleased( const OIS::MouseEvent &arg, OIS::MouseButtonID id );

	private:

		std::map<ID, MessageObjectNode*>	items;
		std::map<ID, MessageObjectNode*>	players;
		MessageObjectNode*					_myPlayer;
		

		virtual void onReceiveControlMessage(ControlMessage *receivedMessage,boost::asio::ip::udp::endpoint senderEndpoint);
		virtual void onReceivePlayerMessage(PlayerMessage *receivedMessage,boost::asio::ip::udp::endpoint senderEndpoint);
		virtual void onReceiveItemMessage(ItemMessage *receivedMessage,boost::asio::ip::udp::endpoint senderEndpoint);
		//void								checkNewObjects();
		//void								updateObjects();
		void								createGui();
		void								createCoordinateSystem();
		void								connectToServer(std::string serverIpAdress);
		void								createLevel();

		void								handleCameraFollowing();


		ControlMessage*						_controlMessage;
		bool								_isGameStarted;
		OgreBites::Label*					_ipInputLabel;

		Ogre::SceneNode*					_coordinateSystemSceneNode;

		//Objects
		Level*								_level;
		
};
